<template>
    <div>
        <mt-field label="姓名" placeholder="请输入姓名" v-model="username" :disabled='!isEditing'></mt-field>
        <mt-field label="年龄" placeholder="请输入您的电话号码" type="number" v-model="age" :disabled='!isEditing'></mt-field>
        <mt-field label="电话" placeholder="请输入电话号码" type="tel" v-model="phone" :disabled='!isEditing'></mt-field>
        <mt-field label="住址" placeholder="请输入住址" type="text" v-model="addr" :disabled='!isEditing'></mt-field>
        <div class="button">
            <wv-button type="primary" v-if="!isEditing" @click="edit">编辑</wv-button>
            <wv-button type="primary" v-else :is-loading='loading' @click="save">保存</wv-button>
        </div>
    </div>
</template>
<script>
import axios from 'axios'
export default {
    name: 'user',
    data() {
        return {
            username: '',
            age: '',
            phone: '',
            addr: '',
            isEditing: false,
            loading: false
        }
    },
    created: function () {},
    methods: {
        getUserInfo() {
            const _this = this
            axios
                .get('/api/expressOrder/getOrderListByOpenId', {
                    params: {
                        openId: 'o0bQvxJ3ONE1oLUody-xo3cKdMwg'
                    }
                })
                .then(res => {
                    if (res.data) {
                        _this.username = res.data.username
                        _this.age = res.data.age
                        _this.phone = res.data.phone
                        _this.addr = res.data.addr
                    }
                })
                .catch(error => {
                    console.log(error)
                })
        },
        edit() {
            this.isEditing = true
        },
        save() {
            const _this = this
            _this.loading = true
            axios
                .get('/api/expressOrder/getOrderListByOpenId', {
                    params: {
                        openId: 'o0bQvxJ3ONE1oLUody-xo3cKdMwg'
                    }
                })
                .then(res => {
                    _this.loading = false
                    if (res.data) {
                        // TopTips({
                        //     message: '提示信息',
                        //     duration: 5000
                        // })
                    }
                })
                .catch(error => {
                    console.log(error)
                })
        }
    }
}
</script>
<style>
.button {
    margin: 10px;
}
</style>
